#include <iostream>
#include <vector>
#include <queue>
using namespace std;

// Definition for a binary tree node.
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

// Definition for singly-linked list.
struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    vector<ListNode*> listOfDepth(TreeNode* tree) {
        vector<ListNode*> res;
        if(!tree) return res;
        queue<TreeNode*> q;
        q.push(tree);
        while(!q.empty())
        {
            ListNode* head = nullptr;
            ListNode* prev = nullptr;
            int currSize = q.size();
            for(int i = 0;i < currSize;++i)
            {
                TreeNode* currNode = q.front();
                ListNode* newNode = new ListNode(currNode->val);
                q.pop();
                if(!head) head = newNode;
                else prev->next = newNode;
                prev = newNode;
                if(currNode->left) q.push(currNode->left);
                if(currNode->right) q.push(currNode->right);
            
            } 
            res.push_back(head);        
        }
        return res;
    }
};

int main()
{
    return 0;
}